#ifndef QPROPERTYLISTVIEW_H
#define QPROPERTYLISTVIEW_H

#include "qbaseitemdelegate.h"

#include <QTreeWidget>

class QAbstractProperty;
class QPropertyListView;

class QPropertyEditorDelegate: public QBaseItemDelegate
{
    Q_OBJECT
public :
    QPropertyEditorDelegate(QPropertyListView* parent):m_listView(parent){}
    QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
protected:
    QPropertyListView   *m_listView;
};

class PC_CORE_SHARED_EXPORT QPropertyListView : public QTreeWidget
{
    Q_OBJECT
public:
    explicit QPropertyListView(QWidget *parent = 0);
    ~QPropertyListView();

    void    setPropertys(const QList<QAbstractProperty*> &propertys);

    void    clearAll();

protected:
    void    updateView();
    void    insertItem(QAbstractProperty* property,QAbstractProperty* parent=NULL);
    void    mousePressEvent(QMouseEvent *event);
    void    drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const;

protected:
    friend class QPropertyEditorDelegate;
signals:
    
protected slots:
    void    property_value_changed(const QVariant &value);
    void    property_changed();
protected:
    QIcon                                                   m_expandIcon;
    QList<QAbstractProperty*>                               m_propertys;
    QMap<QString,QTreeWidgetItem*>                          m_groupItems;
    QList<QTreeWidgetItem*>                                 m_groups;
    QMap<QAbstractProperty*,QTreeWidgetItem*>               m_propertyToItem;
    QMap<QTreeWidgetItem*,QAbstractProperty*>               m_itemToProperty;
};

#endif // QPROPERTYLISTVIEW_H
